package cn.innosmart.aq.view.activity.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import cn.innosmart.aq.R;
import cn.innosmart.aq.application.AQApplication;
import cn.innosmart.aq.customize.CustomsizeDialog;
import cn.innosmart.aq.customize.DetailLoadingDialog;

/**
 * Created by David on 2015/6/12.
 */
public class ConnectBaseActivity extends BaseActivity {
    private IntentFilter intentFilter;
    private MyReceiver myReceiver;
    private CustomsizeDialog connectErrorDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myReceiver = new MyReceiver();
        intentFilter = new IntentFilter();
        intentFilter.addAction("cn.innosmart.aq.CONNECT_LOST");
        intentFilter.addAction("cn.innosmart.aq.CONNECT_LOST");
        registerReceiver(myReceiver, intentFilter);
    }

    @Override
    protected void onDestroy() {
        if (myReceiver != null)
            unregisterReceiver(myReceiver);
        super.onDestroy();
    }



    public void connectLost() {
        Intent i = new Intent("cn.innosmart.aq.CONNECT_LOST");
        sendBroadcast(i);
    }

    public void showConnectErrorDialog(String msg) {
        if (connectErrorDialog == null) {
            connectErrorDialog = new CustomsizeDialog(this);
            connectErrorDialog.setTitle(getString(R.string.dialog_title_alert));
            connectErrorDialog.setCancelable(false);
        }
        connectErrorDialog.setContent(msg);
        connectErrorDialog.setPositiveButton(getString(R.string.sure), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                connectErrorDialog.dismiss();
                exit();
            }
        });
        connectErrorDialog.show();
    }


    public class MyReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
        }
    }
}
